package juc.Lock.reentrantLock;

import java.util.concurrent.locks.ReentrantLock;

public class demo1 {
    private static int num=0;
    private static ReentrantLock lock=new ReentrantLock();
    private static void show(){
        lock.lock();
        lock.lock();
        try {
            num++;
        }finally {
            lock.unlock();
            lock.unlock();
        }
    }

    static class thread extends Thread{
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                demo1.show();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        thread t1 = new thread();
        thread t2 = new thread();
        thread t3 = new thread();
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();

        System.out.println(demo1.num);
    }
}
